using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Ent.Web.Helper;
using System.Collections.Generic;
using Ent.Voice.Nomination;
using Ent.Web.WebControl;

public partial class Member_Message : System.Web.UI.Page
{
    int count = 3;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["USERID"] == null)
            return;
        PopulateList();
    }
    private void PopulateList()
    {
        try
        {
            int pi = MathFunction.ConvertToInteger(Request.QueryString["pi"], 0);
            pi = pi == 0 ? 1 : pi;
            int start = (pi - 1) * count + 1;

            int total = 1;
            int pageCount = LoadEntries(ref total, start);
            lblHeader.Text = ResourceHelper.Get("MSG_SearchHeader") + " " + start.ToString() + " to " + Convert.ToInt32(start + pageCount - 1) + " of " + total.ToString() + " records.";
            SetNavigation(pi, total, start);
        }
        catch (Exception exc)
        {
            Common.ErrorPage(exc);
        }
    }
    private void SetNavigation(int pi, int total, int start)
    {
        Dictionary<string, string> kvList = new Dictionary<string, string>();
        kvList.Add("pi", "");
        btnPrev.Visible = false;
        btnNext.Visible = false;
        if (pi > 1)
        {
            btnPrev.Visible = true;
            kvList["pi"] = Convert.ToString(pi - 1);
            btnPrev.Attributes.Add("onclick", "javascript:window.location.href='" + Common.ResetUrl(kvList) + "'");
        }
        if (total >= start + count)
        {
            btnNext.Visible = true;
            kvList["pi"] = Convert.ToString(pi + 1);
            btnNext.Attributes.Add("onclick", "javascript:window.location.href='" + Common.ResetUrl(kvList) + "'");
        }
    }
    private int LoadEntries(ref int total, int startIndex)
    {
        Entry[] entries = Entry.Search(EntryFilter.User, Session["USERID"].ToString(), "", startIndex, count, "Entered", true, StringHelper.ConvertToString(Session["USERID"]), ref total);
        if (entries != null && entries.Length > 0)
        {
            TableCell tc = new TableCell();
            TableRow tr = new TableRow();
            Page p = (Page)this;
            for (int i = 0; i < entries.Length; i++)
            {
                DashEntry de = (DashEntry)Common.CreateDashEntry(ref p, (Entry)entries.GetValue(i), EntryMode.HomePage);
                de.MediaFile = ConfigurationManager.AppSettings["BaseUrl"] + "/Images/dj/play.gif";
                tc = new TableCell();
                tc.Controls.Add(de);
                tc.VerticalAlign = VerticalAlign.Top;
                tc.Height = Unit.Percentage(100);
                tr.Cells.Add(tc);
                tblEntries.Rows.Add(tr);
                tr = new TableRow();
            }
            lblMyNominations.Visible = false;
            return entries.Length;
        }
        else
        {
            lblMyNominations.Text = Common.GetAlertText(ResourceHelper.Get("MSG_NoNominationSubmitted"));
            tblEntries.Visible = false;
            return 0;
        }
    }
}
